package com.franklin.maven.localcleaner.ui.tree;

import com.franklin.maven.localcleaner.api.swing.tree.BaseSimpleNode;
import com.intellij.ui.tree.BaseTreeModel;

import java.util.Collections;
import java.util.List;

/**
 * 自定义数据Maven Tree Model
 * @author Franklin
 * @since 2022/04/05 17:38
 */
public class MavenTreeModel extends BaseTreeModel<BaseSimpleNode> {

    private final MavenNode mavenNode;

    public MavenTreeModel(MavenNode mavenNode, List<MavenJarNode> mavenJarNodeList) {
        this.mavenNode = mavenNode;
        this.mavenJarNodeList = mavenJarNodeList;
    }
    private final List<MavenJarNode> mavenJarNodeList;

    @Override
    public List<? extends BaseSimpleNode> getChildren(Object parent) {
        if (parent instanceof MavenJarNode){
            return Collections.emptyList();
        }
        this.mavenNode.setChildrenNodeList(this.mavenJarNodeList);
        return this.mavenJarNodeList;
    }

    @Override
    public Object getRoot() {
        return this.mavenNode;
    }

}
